/**
 * @PROJECT 
 * @DATE 2018年7月10日 下午7:59:04
 * @AUTHOR LUYU
 */
package com.kool.tlwp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.kool.tlwp.bean.OptionVo;
import com.kool.tlwp.exception.AppException;

/**
 * @DESCRIBE
 * @AUTHOR LUYU
 * @DATE 2018年7月10日 下午7:59:04
 *
 */
public class GlobalDefineDao {
	protected Connection connection = null;
	protected static Logger logger = Logger.getLogger("DAO");

	public GlobalDefineDao() {
	}

	public GlobalDefineDao(Connection connection) {
		this.connection = connection;
	}

	public List<OptionVo> select(String field) throws SQLException, AppException {
		if (null == field) {
			throw new AppException("condition could not be null!");
		}
		List<OptionVo> listRet = new ArrayList<OptionVo>();

		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SGD_FIELD,SGD_VALUE,SGD_DSP FROM SY_GLOBAL_DEFINE ");
		sbSql.append(" WHERE SGD_FIELD=? ");

		String sql = sbSql.toString();
		logger.debug(sql);

		PreparedStatement state;
		state = connection.prepareStatement(sql);

		state.setString(1, field);

		ResultSet rs = state.executeQuery();
		while (rs.next()) {
			OptionVo result = new OptionVo();
			result.setField(rs.getString("SGD_FIELD"));
			result.setValue(rs.getString("SGD_VALUE"));
			result.setDsp(rs.getString("SGD_DSP"));
			listRet.add(result);
		}

		return listRet;
	}

}
